/**************************************************************************
Copyright (C) 2008-2010 United States Government. All rights reserved. 

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
****************************************************************************/
package rage

import rage.ConverterService
import rage.RageTagLib
import grails.test.*;
import org.codehaus.groovy.grails.commons.ConfigurationHolder;

class RageTagLibTests extends TagLibUnitTestCase {

	protected void setUp() {
		super.setUp();
	}

	protected void tearDown() {
		super.tearDown();
	}

	void testRGBToBGR() {
		String testRgbColor = "0000fd";
		tagLib.rgbToBGR([:]) {-> testRgbColor};

		assertEquals("fd0000", tagLib.out.toString());
	}

	void testEncodeParam() {

		//Set up mock for converterService
		String encodedParam  = "http://localhost/site?this=aamp;that=b";
		def converterServiceMock = mockFor(ConverterService);
		converterServiceMock.demand.encodeParam(1..1) {String arg1 -> 
			return encodedParam
		};
		tagLib.converterService = converterServiceMock.createMock();

		tagLib.encodeParam([:]) {-> "http://localhost/site?this=a&that=b"};
		assertEquals(encodedParam, tagLib.out.toString());
	}

	void testRageServerURL() {

		//Set up mock configuration
		String rageServerURL = "localhost:8080/RAGE";
		def mockedConfig = new ConfigObject();
		mockedConfig.rage.server.url = rageServerURL;
		ConfigurationHolder.config = mockedConfig;

		tagLib.rageServerURL([:], null);

		assertEquals(rageServerURL, tagLib.out.toString());
	}
}
